extends Bullet



@onready var animation_player: AnimationPlayer = $AnimationPlayer
# @onready var _player: Player = get_tree().get_first_node_in_group("player")

var _is_back: bool


func _fly_trace() -> void:
    if not _is_back:
        if global_position.distance_squared_to(start_pos) > fly_range ** 2:
            _is_back = true

            # 返回时造成的伤害减半
            damage_sender.damage_info.damage *= 0.5
    
    else:
        direction = global_position.direction_to(Global.get_player().center_position())
        if global_position.distance_squared_to(Global.get_player().center_position()) < 4 ** 2:
            _is_back = false
            _flying = false
            _expire()

    global_position += speed * direction * get_process_delta_time()


func setup(damage_info: DamageInfo, speed_: float, fly_range_: float, start_pos_: Vector2, direction_: Vector2, hit_effect_op_: ObjectPool) -> void:
    super.setup(damage_info, speed_, fly_range_, start_pos_, direction_, hit_effect_op_)
    damage_info.handled_count = -1
    scale.y = sign(direction.x) * abs(scale.y)
    _is_back = false
    animation_player.seek(0)
    animation_player.play("fly")
